const { addChannel, getChannel, getChannelByName } = require("../services/ChannelService");

class ChannelController {

  // 创建用户头像
  async addChannel (ctx) {
    const channel = ctx.request.body;
    const count = await getChannelByName(channel.name);
    if (count.length) {
      ctx.body = {
        code: 10001,
        msg: '该频道名称已存在',
      }
      return;
    }
    const result = await addChannel(channel)
    if (result) {
      ctx.body = {
        code: 200,
        msg: '添加频道成功'
      }
    } else {
      ctx.body = {
        code: 10001,
        msg: '添加频道失败'
      }
    }
  }

  async getChannel (ctx) {
    const count = await getChannel()
    ctx.body = {
      code: 200,
      msg: '获取频道成功',
      data: count
    }
  }
}

module.exports = new ChannelController()